<template>
  <section class="h100 callBack-panel">
    <van-row class="content" v-if="this.paySuccess===1">
      <img src="../../assets/images/icon/success.png"/>
      <p>恭喜你，充值成功</p>
    </van-row>

    <van-row class="content" v-if="this.paySuccess===2">
      <img src="../../assets/images/icon/fail.png"/>
      <p>很抱歉，充值失败</p>
    </van-row>

    <van-row class="content" v-if="this.paySuccess===3">
      <img src="../../assets/images/icon/loading.gif"/>
      <p>等待支付结果...</p>
    </van-row>

    <van-row class="pay-footer">
      <div class="form-btns" @click="toGameBack()">返回游戏</div>
    </van-row>
  </section>
</template>

<script>
import {BRNative} from "../../utils/brNative";

export default {
  data() {
    return {
      callBackData: '',
      orderNum: 'no',
      paySuccess: 3,
      reLoadTimer: null,
      isReloadStatus: 2,
    }
  },
  created() {
    this.getLoad();
  },
  methods: {
    //初始化加载
    getLoad() {
      this.callBackData = this.$route.query.data;
      this.hideCloseButtonWeb();
      this.getPayStatus();
    },

    //返回游戏
    getPayStatus() {
      let params = {
        callBackData: this.callBackData,
      }
      this.$http(window.config.payHomeApi + '/game/callback/check', params, "post", false).then((res) => {
        let code = res.code;
        if (code !== 1) {
          this.BRToast(res.msg);
          return;
        }
        let resData = res.data;
        this.paySuccess = resData['paySuccess'];
        this.orderNum = resData['orderNum'];
        if (this.paySuccess === 3) {
          clearInterval(this.reLoadTimer);
          this.reLoadTimer = setInterval(() => {
            this.reLoadPayStatus();
          }, 3000);
        } else {
          if (this.isReloadStatus === 1) {
            clearInterval(this.reLoadTimer);
          }
        }
      });
    },
    //返回游戏
    reLoadPayStatus() {
      this.isReloadStatus = 1;
      this.getPayStatus();
    },
    //返回游戏
    toGameBack() {
      BRNative.gamePayFinish(this.orderNum, this.paySuccess);
    },
    //隐藏客户端的关闭按钮
    hideCloseButtonWeb() {
      BRNative.hideCloseButton();
    }
  }
};
</script>

<style lang='less'>
@import "../../assets/css/gamePay/index.less";
</style>
